<?php
$link = MySQL_connect('localhost','root','')
			or die (MySQL_error());
		MySQL_select_db('phoimau_db')
			or die (MySQL_error());

$query = "SELECT * FROM categories";
		
function Cache_Sql($name,$sql)
{
	$query = $sql;
	$file = $name.'.txt';
	$expire = 86400; // 24 hours
	if (file_exists($file) &&
		filemtime($file) > (time() - $expire)) {
		$records = unserialize(file_get_contents($file));
	} else {		
		$result = MySQL_query($query)
			or die (MySQL_error());
		while ($record = MySQL_fetch_array($result) ) {
			$records[] = $record;
		}
		$OUTPUT = serialize($records);
		$fp = fopen($file,"w");
		fputs($fp, $OUTPUT);
		fclose($fp);
	} // end else
	return $records;
}


$a = Cache_Sql("cachedo",$query);

foreach($a as $b){
	echo $b['category_name'];
}

?>
